/*
 * Copyright (C), 2007-2018, 铭师堂教育科技有限公司
 * FileName: GlobalExceptionHandler.java
 * Author:   zhaoyi
 * Date:     2018年4月3日 下午3:04:46
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.secsbrain.engine.web.exception;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

import com.secsbrain.common.ErrorCodeEnum;
import com.secsbrain.common.ResponseVo;

/**
 * 全局异常处理器
 *
 * @author zhaoyi
 */
@RestController
@ControllerAdvice
public class GlobalExceptionHandler {
	
    private static final Logger logger = LoggerFactory.getLogger(GlobalExceptionHandler.class);
	
	@ExceptionHandler(value = Exception.class)
    public ResponseVo<?> defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
        logger.error("---DefaultException Handler---Host {} invokes url {} ERROR: {}", req.getRemoteHost(), req.getRequestURL(), e.getMessage());
        return ErrorCodeEnum.ERROR_COMMON_SYSTEM.getResponseVo(e.getMessage());    
    }
	
	@ExceptionHandler(value = IllegalArgumentException.class)
    public ResponseVo<?> illegalArgumentErrorHandler(HttpServletRequest req, Exception e) throws Exception {
        logger.error("---IllegalArgumentException Handler---Host {} invokes url {} ERROR: {}", req.getRemoteHost(), req.getRequestURL(), e.getMessage());
        return ErrorCodeEnum.ERROR_COMMON_CHECK.getResponseVo(e.getMessage());
    }
	
}
